const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: path.join(__dirname, 'src/main.js'), // 入口文件
    output: {
        filename: '[name].[hash:8].js',
        path: path.resolve(__dirname, "dist")
    },
    module: {
        rules: [

            {
                test: /\.vue$/,
                exclude: /node_modules/,
                use: ['vue-loader']
            },

            {
                test: /\.(png|jpg|svg|webp|jpeg)$/,
                exclude: /node_modules/,
                use: {
                    loader: "url-loader",
                    options: {
                        esModule: false,
                        limit: 50 * 1024,
                        name: "[hash:8].[ext]"
                    }
                }
            },
            {
                test: /\.js/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: "eslint-loader",
                        options: {
                            fix: true
                        }
                    },
                    // {
                    //     loader: "babel-loader",
                    //     options: {
                    //         presets: [
                    //             [
                    //                 "@babel/preset-env",
                    //                 {
                    //                     useBuiltIns: "usage",
                    //                     corejs: {
                    //                         version: 3
                    //                     },
                    //                     targets: {
                    //                         chrome: "60",
                    //                         firefox: "50",
                    //                         ie: "9",
                    //                         safari: "10",
                    //                         edge: "17"
                    //                     }
                    //                 }
                    //             ]
                    //         ]
                    //     }
                    // }
                ]
            },
        ]
    },

    plugins: [
        new HtmlWebpackPlugin({
            templateParameters: {
                BASE_URL: './'
            },
            title: "zzy Webpack Vue App",
            template: path.join(__dirname, "./public/index.html"),//指定模版文件路径
            filename: "index.html"//设置内存中页面名称
        }),

        new VueLoaderPlugin(),
        new CleanWebpackPlugin(),

    ]
}